#Ruby Version of a main loop, for event based programming.
#I don't know if there is a better way to do this just yet.

#This entire project will be reorganized several times, guaranteed.

#Author:  Sam Robertson
#Modified: 1/13/2012

require "./Calc_Input.rb"
require "./History.rb"

#create our Calc_Input object
calculator = Calc_Input.new()
#create our command history, maybe this should be more... object oriented?
history = History.new()

#set up the program loop
exit = 0
puts "Starting RubyCalc version 0.1..."
while (exit == 0)
  print("#{history.length + 1}->")
  input = gets.chomp
  if (input == "exit")
    exit = 1
    next
  end
  #START the block handles the command history portion of the calculator
  if (input =~ /^!/)
    puts history.process(input)
  else
    history.push(input)
  end
  #END the block implementing command history!  
  #else, we're going to assume the user wants to use the calculator, and attempt to build a symbol tree...  
  if(input != "" and !(input =~ /^!/))
    result = calculator.calculate(input)
    puts result    
  end 
end
puts "exiting..."

